Skip to content

Conversation

@riftzen-bit
Copy link
Contributor

Fixes #9364

Problem

When using Claude models with Extended Thinking enabled, multi-turn conversations with tool use fail with:

messages.X.content.0.type: Expected 'thinking' or 'redacted_thinking', but found 'tool_use'

Root Cause

The normalizeMessages function filters empty content but does not reorder parts to ensure reasoning blocks come before tool-call blocks in assistant messages.

Solution

Added sorting logic for assistant messages in the Anthropic-specific block. Parts are now ordered by priority:

  • reasoning: 0 (first)
  • text: 1
  • tool-call: 2
  • everything else: 3

This ensures compliance with Anthropic's Extended Thinking API requirements.

References

… messages

Fixes #9364

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found one potentially related PR:

Related PR:

This could be relevant context for understanding how thinking blocks are handled across the codebase, though it may not be a direct duplicate since your PR specifically addresses the ordering issue in normalizeMessages for Anthropic's API requirements.

@rekram1-node
Copy link
Collaborator

When did you encounter this issue?

Can you share the session?

Run opencode export > session.json in your TERMINAL (not the tui) and then send session export of it

@riftzen-bit
Copy link
Contributor Author

I encountered this problem this afternoon and it hasn't been fixed yet. I'm trying to figure it out, but it doesn't seem to be working. Because I don't know where the problem is coming from.

@riftzen-bit
Copy link
Contributor Author

session.json

@rekram1-node
Copy link
Collaborator

The provided session has no such errors?

@riftzen-bit
Copy link
Contributor Author

I don't know, but I've been encountering it constantly in recent chat messages.

@riftzen-bit
Copy link
Contributor Author

session.json

@rekram1-node
Copy link
Collaborator

Sorry if I wasn't clear, can you export the session in which you encountered this error? Because the sessions you are linking aren't relevant

@riftzen-bit
Copy link
Contributor Author

I've fixed it now, it was due to plugins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Claude Extended Thinking: assistant message content order causes API error

2 participants